package de.duester.genealogy.model.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import de.greenrobot.dao.AbstractDaoMaster;
import de.greenrobot.dao.identityscope.IdentityScopeType;

import de.duester.genealogy.model.dao.PersonDao;
import de.duester.genealogy.model.dao.EventCodeDao;
import de.duester.genealogy.model.dao.EventDao;
import de.duester.genealogy.model.dao.EventAttributeDao;
import de.duester.genealogy.model.dao.DocumentDao;
import de.duester.genealogy.model.dao.PlaceCodeDao;
import de.duester.genealogy.model.dao.PlaceDao;
import de.duester.genealogy.model.dao.DateDao;
import de.duester.genealogy.model.dao.RoleCodeDao;
import de.duester.genealogy.model.dao.PersonRoleCodeDao;
import de.duester.genealogy.model.dao.PersonEventDao;
import de.duester.genealogy.model.dao.PersonDocumentDao;
import de.duester.genealogy.model.dao.EventDocumentDao;
import de.duester.genealogy.model.dao.EventPlaceDao;
import de.duester.genealogy.model.dao.EventDateDao;
import de.duester.genealogy.model.dao.EventStringDao;
import de.duester.genealogy.model.dao.DocumentPlaceDao;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * Master of DAO (schema version 1): knows all DAOs.
*/
public class DaoMaster extends AbstractDaoMaster {
    public static final int SCHEMA_VERSION = 1;

    /** Creates underlying database table using DAOs. */
    public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) {
        PersonDao.createTable(db, ifNotExists);
        EventCodeDao.createTable(db, ifNotExists);
        EventDao.createTable(db, ifNotExists);
        EventAttributeDao.createTable(db, ifNotExists);
        DocumentDao.createTable(db, ifNotExists);
        PlaceCodeDao.createTable(db, ifNotExists);
        PlaceDao.createTable(db, ifNotExists);
        DateDao.createTable(db, ifNotExists);
        RoleCodeDao.createTable(db, ifNotExists);
        PersonRoleCodeDao.createTable(db, ifNotExists);
        PersonEventDao.createTable(db, ifNotExists);
        PersonDocumentDao.createTable(db, ifNotExists);
        EventDocumentDao.createTable(db, ifNotExists);
        EventPlaceDao.createTable(db, ifNotExists);
        EventDateDao.createTable(db, ifNotExists);
        EventStringDao.createTable(db, ifNotExists);
        DocumentPlaceDao.createTable(db, ifNotExists);
    }
    
    /** Drops underlying database table using DAOs. */
    public static void dropAllTables(SQLiteDatabase db, boolean ifExists) {
        PersonDao.dropTable(db, ifExists);
        EventCodeDao.dropTable(db, ifExists);
        EventDao.dropTable(db, ifExists);
        EventAttributeDao.dropTable(db, ifExists);
        DocumentDao.dropTable(db, ifExists);
        PlaceCodeDao.dropTable(db, ifExists);
        PlaceDao.dropTable(db, ifExists);
        DateDao.dropTable(db, ifExists);
        RoleCodeDao.dropTable(db, ifExists);
        PersonRoleCodeDao.dropTable(db, ifExists);
        PersonEventDao.dropTable(db, ifExists);
        PersonDocumentDao.dropTable(db, ifExists);
        EventDocumentDao.dropTable(db, ifExists);
        EventPlaceDao.dropTable(db, ifExists);
        EventDateDao.dropTable(db, ifExists);
        EventStringDao.dropTable(db, ifExists);
        DocumentPlaceDao.dropTable(db, ifExists);
    }
    
    public static abstract class OpenHelper extends SQLiteOpenHelper {

        public OpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory, SCHEMA_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
            createAllTables(db, false);
        }
    }
    
    /** WARNING: Drops all table on Upgrade! Use only during development. */
    public static class DevOpenHelper extends OpenHelper {
        public DevOpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
            dropAllTables(db, true);
            onCreate(db);
        }
    }

    public DaoMaster(SQLiteDatabase db) {
        super(db, SCHEMA_VERSION);
        registerDaoClass(PersonDao.class);
        registerDaoClass(EventCodeDao.class);
        registerDaoClass(EventDao.class);
        registerDaoClass(EventAttributeDao.class);
        registerDaoClass(DocumentDao.class);
        registerDaoClass(PlaceCodeDao.class);
        registerDaoClass(PlaceDao.class);
        registerDaoClass(DateDao.class);
        registerDaoClass(RoleCodeDao.class);
        registerDaoClass(PersonRoleCodeDao.class);
        registerDaoClass(PersonEventDao.class);
        registerDaoClass(PersonDocumentDao.class);
        registerDaoClass(EventDocumentDao.class);
        registerDaoClass(EventPlaceDao.class);
        registerDaoClass(EventDateDao.class);
        registerDaoClass(EventStringDao.class);
        registerDaoClass(DocumentPlaceDao.class);
    }
    
    public DaoSession newSession() {
        return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
    }
    
    public DaoSession newSession(IdentityScopeType type) {
        return new DaoSession(db, type, daoConfigMap);
    }
    
}
